package top.ffhome.system.config;

import java.util.Properties;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;

/** 验证码配置 */
@Configuration
public class KaptchaConfig {
	@Value(value = "${kaptcha.border:no}")
	private String border;
	@Value(value = "${kaptcha.textproducer.font.color:black}")
	private String fontColor;
	@Value(value = "${kaptcha.textproducer.char.space:5}")
	private String space;
	@Value(value = "${kaptcha.textproducer.char.length:4}")
	private String length;
	@Value(value = "${kaptcha.textproducer.char.string:0123456789}")
	private String string;

	@Bean
	public DefaultKaptcha producer() {
		Properties properties = new Properties();
		properties.put("kaptcha.border", border);
		properties.put("kaptcha.textproducer.font.color", fontColor);
		properties.put("kaptcha.textproducer.char.space", space);
		properties.put("kaptcha.textproducer.char.length", length);
		properties.put("kaptcha.textproducer.char.string", string);
		Config config = new Config(properties);
		DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
		defaultKaptcha.setConfig(config);
		return defaultKaptcha;
	}
}
